<?php 

Class ModuleSubscriptionResult extends CmsCustomModule {
	
	private function getAgeData(){
		$datas = array();
		$age_list = AC::$age_list;
		unset($age_list[0]);
		unset($age_list['all']);
		$captures = array('New', 'Renew');
		//for($i=1; $i<count($age_list) +1; $i++){
		for($i=0; $i<2; $i++){
			$data = array();
			for($j=0; $j<7; $j++){
				$data[] = rand(99, 999);
			}
			$datas[] = array('data'=> $data, 'capture'=>$captures[$i]);
		}
		return $datas;
	}
	private function getAgeItemHTML(){
		$datas = array();
		$labels = array();
		$rowTrs = array();
		for($i=0; $i<7; $i++){
			$tmp_time = time() - (6 - $i)*24*3600;
			$labels[] = date("m-d", $tmp_time);
			$rowTrs[] = '<tr><td class="textfield">'.date("Y-m-d", $tmp_time).'</td><td class="num">9,999,999,999</td><td class="num">9,999,999,999</td></tr>';
		}
		$datas = json_encode($this->getAgeData());
		$labels = json_encode($labels);
		$rowTrs = implode('', $rowTrs);
		return "<input type=\"hidden\" class=\"canvasCurveLines\" value='{$datas}' labels='{$labels}' />"
			.'<table width="100%" border="0"><tr class="textfield weight" bgcolor="#CCC"><td>Day</td><td class="num">New</td><td class="num">Renew</td></tr>'.$rowTrs.'</table>';
	}
	private function getCountryItemHTML(){
		$datas = array();
		$captures = array('New', 'Renew');
		$rowTrs = array();
		for($i=0; $i<2; $i++){
			$data = array();
			for($j=0; $j<36; $j++){
				$data[] = rand(99, 999);
			}
			$datas[] = array('data'=> $data, 'capture'=>$captures[$i]);
		}
		$labels = array();
		for($i=0; $i<36; $i++){
			$tmp_time = time() - (36 - $i)*24*3600;
			$labels[] = date("m-d", $tmp_time);
			$rowTrs[] = '<tr><td class="textfield">'.date("Y-m-d", $tmp_time).'</td><td class="num">9,999,999,999</td><td class="num">9,999,999,999</td></tr>';
		}
		$datas = json_encode($datas);
		$labels = json_encode($labels);
		$rowTrs = implode('', $rowTrs);
		return "<input type=\"hidden\" class=\"canvasCurveLines36\" value='{$datas}' width='' labels='{$labels}' />"
			.'<table width="100%" border="0"><tr class="textfield weight" bgcolor="#CCC"><td>Day</td><td class="num">New</td><td class="num">Renew</td></tr>'.$rowTrs.'</table>';
	}
    protected function __renderHead()
    {
		$filters = array('dateby', 'startmonth', 'startyear', 'endmonth', 'endyear', 'startdate', 'enddate', 'country','package','gender','age');
		foreach($_GET as $k=>$v){
			if(in_array($k, $filters)){
				$$k = $v;
			}
		}
		$startmonth = str_pad($startmonth, 2, 0, STR_PAD_LEFT);
		$endmonth = str_pad($endmonth, 2, 0, STR_PAD_LEFT);
		$curr_datetime = date("Y-m-d H:i:s");
		
		$str_date = '';
		if($dateby == 'date'){
			$str_date = "{$startdate} - {$enddate}";
		}else{
			$str_date = "{$startyear} - {$startmonth} to {$endyear} - {$endmonth}";
		}
		
		
		$str_age = array();
		$age = explode(',', $age);
		foreach($age as $k){
			$str_age[] = AC::$age_list[$k];
		}
		$str_age = implode(',', $str_age);
		
		$str_package = '';
		$video_package = array();
			$video_package = AC::$video_plan_package;
		if($package == 0){
			unset($video_package['all']);
			$str_package = 'All ('.implode(', ', $video_package).')';
		}else{
			$tmp = explode(',', $package);
			$tmps = array();
			foreach($tmp as $v){
				$tmps[] = $video_package[$v];
			}
			$str_package = implode(', ', $tmps);
			$video_package = $tmps;
		}
		
		
		$str_gender = AC::$gender_list[$gender];
		$gender_age_list = '';
		
		
		$str_country = transCountry($country);
		$country = json_decode($country);
		$region_country_list = '';
		foreach($video_package as $mpackage){
			/*
			$region_country_list .= "<dt><p>{$mpackage}</p></dt><dt>".$this->getItemHTML($k)."</dt>";
			foreach($country as $k=>$item){
				if(is_object($item)){
					$region_country_list .= $this->getItemHTML($k);
					foreach($item as $k2=>$item2){
						$region_country_list .= $this->getItemHTML($k, $k2);
						foreach($item2 as $item3){
							$k3 = getStatsClass::getCountryByAll($k, $k2, $item3);
							$region_country_list .= $this->getItemHTML($k, $k2, "{$k3}({$item3})");
						}
					}
				}else{
					$region_country_list .= $this->getItemHTML($k);
				}
			}
			*/
		}
		$age_line_datas = array();
		for($i=0; $i<10; $i++){
			$age_line_datas[$i] = $this->getAgeItemHTML();
		}
		
		$country_line_datas = array();
		for($i=0; $i<10; $i++){
			$country_line_datas[$i] = $this->getCountryItemHTML();
		}
		
		$dateby = ucwords( strtolower($dateby));
		
		$this->contents = <<<HTML
	<div id="result" class="subscription_result">
		<div class="hd">
			<div class="utility">
				<a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Export to <a href="#">HTML</a>
			</div>
			<hr />
			<h1>Plan Subscription Report</h1>
			<div class="time">{$curr_datetime}</div><br />
			<div><b>By {$dateby}:</b> {$str_date}</div>
			<div><b>Subscription Plan:</b> {$str_package}</div>
			<div><b>Gender:</b> {$str_gender}</div>
			<div><b>Age Group:</b> {$str_age}</div>
			<table class="nob"><tr><td valign="top" width="100"><b class="tit">Region/Country:</b>&nbsp;</td><td>{$str_country}</td></tr></table>
		</div>
		<div class="bd">
<!--dl>
	<dt>Gender & Age Group</dt>
	{$gender_age_list}
</dl>

<dl>
	<dt>Region / Country</dt>
	{$region_country_list}
</dl-->


<table border="0" cellpadding="0" cellspacing="0">
	<!--- Gender & Age Group start -->
  <tbody>
  <tr>
    <td colspan="5" class="tit"><div align="center"><strong>Gender &amp; Age Group </strong></div></td>
  </tr>
    <tr class="weight">
<td width="194">Plan:24hours</td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr>
<td colspan="5"><div align="center">
  <p><strong>Gender:M</strong></p>
  <p>{$age_line_datas[0]}</p>
  <p><strong>Gender:F</strong></p>
  <p>{$age_line_datas[1]}</p>
</div></td>
    </tr>
      <tr>
<td width="194"></td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr class="weight">
<td width="194">Plan:1 month</td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr>
<td colspan="5"><div align="center">
  <p><strong>Gender:M</strong></p>
  <p>{$age_line_datas[2]}</p>
  <p><strong>Gender:F</strong></p>
  <p>{$age_line_datas[3]}</p>
</div></td>
    </tr>
      <tr>
<td width="194"></td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
	<!--- Gender & Age Group end -->
  <tr>
    <td colspan="5" class="tit"><div align="center"><strong>Region/Country</strong></div></td>
  </tr>
    <tr class="weight">
<td width="194">Plan:24hours</td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr>
<td colspan="5"><div align="center">
  <p><strong>Asia - China(CN)</strong></p>
  <p>{$country_line_datas[0]}</p>
  <p><strong>Asia - Hong Kong(HK)</strong></p>
  <p>{$country_line_datas[1]}</p>
</div></td>
    </tr>
      <tr>
<td width="194"></td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr class="weight">
<td width="194">Plan:1 month</td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
    <tr>
<td colspan="5"><div align="center">
  <p><strong>Asia - China(CN)</strong></p>
  <p>{$country_line_datas[2]}</p>
  <p><strong>Asia - Hong Kong(HK)</strong></p>
  <p>{$country_line_datas[3]}</p>
</div></td>
    </tr>
      <tr>
<td width="194"></td>
    <td width="195">&nbsp;</td>
    <td width="117">&nbsp;</td>
    <td width="95">&nbsp;</td>
    <td width="49">&nbsp;</td>
  </tr>
	<!--- Gender & Age Group end -->

</tbody></table>
		</div>
	</div>
HTML;
    }
}
?>